package be.ipl.vingtetun.domaine;

import java.io.Serializable;
import java.util.Random;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@SuppressWarnings("serial")
@Entity
@Table(name="DES", schema="JACK")
public class De implements Serializable {
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	@Min(1)	@Max(Partie.NB_DES)
	@NotNull
	private int numero;
	
	@Max(6) @Min(0)
	private int valeur;
	
	@Transient
	private Random random = new Random();

	public De(int numero) {
		this.numero = numero;
		for (int i = 0; i < numero; i++)
			lancerDe();
	}

	protected De() {
	}

	public int getId() {
		return id;
	}

	public int getNumero() {
		return numero;
	}

	public int getValeur() {
		return valeur;
	}

	public int lancerDe() {
		return valeur = random.nextInt(6) + 1;
	}
}
